import axios from "axios";
import {ElNotification} from "element-plus";
import router from "@/router/index.js";
import {setStorage} from "@/utils/localStorage.js";

const loginMoudle = {
    namespaced:true,
    state:{

    },
    actions:{
        login(context,loginData){loginMoudleRequest(context,loginData)},
    },
    mutations:{
    },
}
export default loginMoudle
function loginMoudleRequest(context,loginData){
    console.log('@@@@@@@', loginData, {});
    axios.get('localhost/login/login',loginData,
        {
            headers:{
                'Content-Type': 'application/json'
            }
        }
    )
        .then(response =>{
            console.log('ssss' ,response)
            console.log('response.data',response.data)
            // console.log('response.data.username',response.data)
            //保存token,用户信息, 用户菜单到浏览器缓存
            localStorage.setItem('token',response.data.token)
            localStorage.setItem('userId',response.data.userId)
            ElNotification({title: 'Success', message: '登陆成功', type:'success'})
            router.push('/homeView')
        })
        .catch(error=>{
            console.log(error)
            ElNotification({title: 'Error', message: error.response.data.error, type:'error'})
        })
}